package com.xd.study.activity;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;

import com.xd.study.R;
import com.xd.study.fragment.DynamicFragment;

/**
 * Created by DGF on 2015/4/24.
 */
public class FragmentTestActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_test);

        RadioGroup radioGroup = (RadioGroup)this.findViewById(R.id.rdo_group_fragment);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rdo_fragment_1://静态加载Fragment
                        Intent intent = new Intent(FragmentTestActivity.this, FragmentStaticActivity.class);
                        FragmentTestActivity.this.startActivity(intent);
                        break;
                    case R.id.rdo_fragment_2://动态加载Fragment
                        Fragment dynamicFragment = new DynamicFragment();
                        FragmentManager fragmentManager = getFragmentManager();
                        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                        fragmentTransaction.add(R.id.layout_fragment, dynamicFragment);
                        //fragmentTransaction.addToBackStack(null);
                        fragmentTransaction.commit();
                        break;
                    case R.id.rdo_fragment_3://生命周期
                        Intent intent3 = new Intent(FragmentTestActivity.this, FragmentLifecycleActivity.class);
                        FragmentTestActivity.this.startActivity(intent3);
                        break;
                    case R.id.rdo_fragment_4://参数传值
                        Intent intent4 = new Intent(FragmentTestActivity.this, FragmentPassValueActivity.class);
                        FragmentTestActivity.this.startActivity(intent4);
                        break;
                }
            }
        });
    }
}
